package cn.whpu.ui;

import cn.whpu.dao.AccountDao;
import cn.whpu.service.AccountService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

/**
 * 模拟一个表现层，调用业务层
 */
public class Client {
    /**
     *   获取spring的Ioc核心容器，并根据id获取对象
     * @param args
     */
    /*
    ApplicationContext的三个常用实现类
    ClassPathXmlApplicationContext
    FileSystemXmlApplicationContext
    AnnotationConfigApplicationContext

    核心容器的两个接口引发出的问题
        ApplicationContext 采用立即加载的方式
        BeanFactory 采取延迟加载的方式，什么时候根据id获取对象，才真正创建对象
    */
    public static void main(String[] args) {
        //获取核心容器对象
        ApplicationContext ac = new ClassPathXmlApplicationContext("bean.xml");
        //根据id获取bean对象
        AccountService as = (AccountService)ac.getBean("accountService");
        AccountDao adao = (AccountDao)ac.getBean("accountDao");

        System.out.println(as);
        System.out.println(adao);
        as.saveAccount();

    }
}
